Count Property (Folders Collection) 

The Count property returns the number of FolderKM47H0 objects in the collection, or a very large number if the exact count is not available. Read-only.

Syntax

objFoldersColl.Count

Data Type

Long

Remarks

The Count property is useful for determining whether a Folders collection is empty or not.

A large collection cannot always maintain an accurate count of its members, and the Count property cannot be used as the collection s size when it has a very large value such as mapiMaxCount. Programmers needing to access individual objects in a large collection are strongly advised to use the Visual Basic For Each statement or the Get methods.

The recommended procedures for traversing a large collection are, in decreasing order of preference:

  1.  Global selection, such as the Visual Basic For Each statement

  2.  The Get methods, particularly GetFirst2M91_LL and GetNextL476GW

  3.  An indexed loop, such as the Visual Basic For ... Next construction

If the message store provider cannot supply the precise number of Folder objects, the OLE Messaging Library returns a very large number for the Count property. On 32-bit platforms, this value is mapiMaxCount, which equals 2^31 - 1, or 2147483647. On other platforms, mapiMaxCount is not defined, and the OLE Messaging Library returns -1. A program on such a platform must be careful that -1 does not prematurely terminate any iteration based on the Count property.

Programmers using an indexed loop terminating on the Count property must also check each returned object for a value of Nothing. The loop must proceed forward from the beginning of the collection, and the index must have initial and increment values of 1. Results are undefined for any other procedure.

The use of the Item109DJ4L property in conjunction with the Count property in a large collection can be seen in the following example.

Example

This code fragment searches for a Folder object called  Resumes :

Dim i As Integer ' loop index / object counter

Dim collFolders as Object ' folders collection; assume already given

If collFolders Is Nothing Then

    ' MsgBox "Folders collection object is invalid"

    ' Exit

End If

' see if collection is empty

If 0 = collFolders.Count Then

    ' MsgBox "No folders in collection"

    ' Exit

End If

' look for folder called  Resumes  in collection

For i = 1 To collFolders.Count Step 1

    If collFolders.Item(i) Is Nothing Then

    ' MsgBox "No such folder found in collection"

    ' Exit ' no more folders in collection

    End If

    If collFolders.Item(i).Name =  Resumes  Then

    ' MsgBox "Desired folder is at index " & i

    ' Exit

    End If

Next i